package com.ssm.studen.service.impl;

import com.ssm.studen.dao.ExamquestiontypeDao;
import com.ssm.studen.model.Examquestiontype;
import com.ssm.studen.service.ExamquestiontypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 考题类型表：
 *          实现业务及流程接口当中的内容
 */
@Service
public class ExamquestiontypeServiceImpl implements ExamquestiontypeService {

    @Autowired
    private ExamquestiontypeDao examquestiontypeDao;


    /**
     * 考题类型表查询
     * @param eqtnum
     * @return
     */
    @Override
    public int selectExamquestionType(int eqtnum) {
        return examquestiontypeDao.selectExamquestionType(eqtnum);
    }


    /**
     * 考题类型表添加
     * @param examquestiontype
     * @return
     */
    @Override
    public int insertExamquestionType(Examquestiontype examquestiontype) {
        int result = 0;
        int examquestionTypeCount = examquestiontypeDao.examquestionTypeIdCount(new Examquestiontype().getEqtnum());
        if(examquestionTypeCount<1){
            int add = examquestiontypeDao.insertExamquestionType(examquestiontype);
            result = add;
        }else{
            result = -1;
        }
        return result;
    }


    /**
     * 考题类型表修改更新
     * @param examquestiontype
     * @return
     */
    @Override
    public int updateExamquestionType(Examquestiontype examquestiontype) {
        /*
         * 业务流程判断
         * */
        int isUpdate = 0;
        try {
            isUpdate = examquestiontypeDao.updateExamquestionType(examquestiontype);
        }catch (Exception e){
            isUpdate = -1;
            //打印更新时报错的情况
            System.out.println("更新考题类型表信息时执行SQL报错的原因是：" + e.getMessage());
        }
        return isUpdate;
    }
}
